﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public sealed class RoyalItemBLL : IRoyalItemBLL
    {
        private static readonly IRoyalItemDAL dal = DataAccess.CreateRoyalItems();

        private RoyalItemInfo royalInfo = new RoyalItemInfo();
        private RoyalItemTypeInfo typeInfo = new RoyalItemTypeInfo();

        public IList<RoyalItemInfo> ListRoyalItems()
        {
            return dal.ListRoyalItems(new RoyalItemInfo(0));
        }
        public IList<RoyalItemInfo> ListRoyalItems(string RoyalItemType)
        {
            typeInfo.Sequence = RoyalItemType.Length > 0 ? Int32.Parse(RoyalItemType) : 0;
            royalInfo.RoyalItemTypes = typeInfo;
            return dal.ListRoyalItems(new RoyalItemInfo(0));
        }
        public IList<RoyalItemInfo> ListRoyalItemsBySequence(int Sequence)
        {
            return dal.ListRoyalItems(new RoyalItemInfo(Sequence));
        }
        public void Insert(string RoyalItemType, string Code, string Name, string NameShort, int CreatedBy)
        {
            typeInfo.Sequence = RoyalItemType.Length > 0 ? Int32.Parse(RoyalItemType) : 0;

            try
            {
                dal.Insert(new RoyalItemInfo(0, Code, Name, NameShort, typeInfo, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string RoyalItemType, string Code, string Name, string NameShort, int UpdatedBy)
        {
            typeInfo.Sequence = RoyalItemType.Length > 0 ? Int32.Parse(RoyalItemType) : 0;

            try
            {
                dal.Update(new RoyalItemInfo(Sequence, Code, Name, NameShort, typeInfo, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
